<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('学生项目管理')"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="data-form">
                <div class="select-list">
                    <ul>
                        <li>
                            <label style="width: 80px">学生姓名：</label>
                            <input type="text" name="childName"/>
                        </li>
                        <li>
                            </label>学员类型：</label>
<!--                            <select name="memberType"  style="margin-right: 25px">-->
<!--                                <option value="1" selected>在读会员</option>-->
<!--                                <option value="0">非会员</option>-->
<!--                                <option value="3">过期会员</option>-->
<!--                                <option value="2">历史会员</option>-->
<!--                            </select>-->
                            <select name="memberType" th:with="type=${@dict.getType('member_status')}">
                                <option value="">请选择</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
<!--                        <li>-->
<!--                            <label style="width: 80px">电话号码：</label>-->
<!--                            <input type="number" name="telephone"/>-->
<!--                        </li>-->
<!--                        <li>-->
<!--                            <label style="width: 80px">学生年龄：</label>-->
<!--                            <input type="number" name="beginAge" placeholder="开始年龄"/>-->
<!--                            <span>-</span>-->
<!--                            <input type="number" name="endAge" placeholder="结束年龄"/>-->
<!--                        </li>-->
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.addTab()">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.editTab()">
                <i class="fa fa-edit"></i> 修改
            </a>
<!--            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()">-->
<!--                <i class="fa fa-remove"></i> 删除-->
<!--            </a>-->
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script th:inline="javascript">
    // 权限
    var informationFlag = [[${@permission.hasPermi('business:childInformation:view')}]];
    var evaluateFlag = [[${@permission.hasPermi('business:evaluateFlag:view')}]];
    var evaluateReportFlag = [[${@permission.hasPermi('business:evaluateReportFlag:view')}]];

    // 字典
    var sexType = [[${@dict.getType('sys_user_sex')}]];
    var memberType = [[${@dict.getType('business_member_type')}]];
    var prefix = ctx + "business/child";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            modalName: "数据",
            queryParams: queryParams,
            columns: [
                {
                    checkbox: true
                },
                {
                    field: 'id',
                    title: 'id',
                },
                {
                    field: 'childName',
                    title: '学员姓名',
                },
                {
                    field: 'phone',
                    title: '手机号码',
                },
                {
                    field: 'sex',
                    title: '性别',
                    align: "center",
                    formatter: function (value, row, index) {
                        if ($.common.isNotEmpty(value)) {
                            return $.table.selectDictLabel(sexType, value);
                        } else {
                            return null;
                        }
                    }
                },
                // {
                //     field: 'telephone',
                //     title: '电话号码',
                // },
                {
                    field: 'age',
                    title: '学员年龄',
                },
                {
                    field: 'isMember',
                    title: '学员类型',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if ($.common.isNotEmpty(value)) {
                            if(value == '0'){
                                actions.push($.common.sprintf("<span class='%s'>%s</span>", "default","储备客户"));
                            }
                            if(value == '1'){
                                actions.push($.common.sprintf("<span class='%s'>%s</span>", "default","在读会员"));
                            }
                            if(value == '2'){
                                actions.push($.common.sprintf("<span class='%s'>%s</span>", "default","历史会员"));
                            }
                            if(value == '3'){
                                actions.push($.common.sprintf("<span class='%s'>%s</span>", "default","过期会员"));
                            }

                        }
                        return actions.join('');
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + evaluateFlag + '" href="javascript:void(0)" onclick="childEvaluate(\'' + row.id + '\',\'' + row.childName + '\',\'' + row.age + '\')"><i class="fa fa-edit"></i>测评</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + evaluateReportFlag + '" href="javascript:void(0)" onclick="childReport(\'' + row.id + '\',\'' + row.childName + '\')"><i class="fa fa-list-ul"></i>测评记录</a> ');
                        // actions.push('<a class="btn btn-success btn-xs ' + evaluateFlag + '" href="javascript:void(0)" onclick="learningEvaluate(\'' + row.id + '\',\'' + row.childName + '\',\'' + row.grade + '\')"><i class="fa fa-edit"></i>学能测评</a> ');
                        // actions.push('<a class="btn btn-success btn-xs ' + evaluateReportFlag + '" href="javascript:void(0)" onclick="learningReport(\'' + row.id + '\',\'' + row.childName + '\')"><i class="fa fa-list-ul"></i>学能测评记录</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function editChildInformation(childId, childName) {
        var url = ctx + "business/childInformation/getInformation/" + childId;
        $.modal.openTab(childName + "的基础信息", url);
    }

    function childEvaluate(childId, childName,age) {
        var intAge = age.split('岁')[0];
        if(Number(intAge)<2 ||Number(intAge)>10 ){
            $.modal.alertWarning("学员年龄没有达到测评条件，请重新确认");
            return;
        }
        $.ajax({
            url: ctx + "business/childQuestion/checkCertificate/"+localStorage.getItem('selectCenterId'),
            type: "get",
            success: function(result) {
                if (result.code == 0) {
                    if(result.data=='false'){
                        $.modal.alertWarning("在该校区无测评证书");
                        return;
                    }else {
                        var url = ctx + "business/childQuestion/getChildQuestion/" + childId;
                        $.modal.openTab(childName + "的测评", url);
                    }
                }
            }
        })

    }
    function learningEvaluate(childId, childName,grade) {
        if(grade ==undefined || grade =='' || grade =='null'){
            $.modal.alertWarning("该学员未设置年级，请登陆运营管理系统进行设置！");
            return;
        }else {
            var url = ctx + "business/childQuestion/learningEvaluate/" + childId;
            $.modal.openTab(childName + "的测评", url);
        }
    }

    function childReport(childId, childName) {
        $.ajax({
            url: ctx + "business/childQuestion/checkCertificate/"+localStorage.getItem('selectCenterId'),
            type: "get",
            success: function(result) {
                if (result.code == 0) {
                    if(result.data=='false'){
                        $.modal.alertWarning("在该校区无测评证书");
                        return;
                    }else {
                        var url = ctx + "business/childReport/childReport/" + childId;
                        $.modal.openTab(childName + "的测评记录", url, 1200, null, null);
                    }
                }
            }
        })

    }
    function learningReport(childId,childName) {
        var url = ctx + "business/learningReport/learningReport/" + childId+"/"+"1";
        $.modal.openTab(childName + "的测评记录", url, 1200, null, null);
    }

    function queryParams(params) {
        var selectIndex = window.parent.document.getElementById('parentSchoolList').selectedIndex;
        if (selectIndex >= 0) {
            var centerId = window.parent.document.getElementById('parentSchoolList').options[selectIndex].value;
            var search = $.table.queryParams(params);
            search.centerId = centerId;
        }
        return search;
    }

</script>
</body>

</html>